function x = SOR(A,b,w,error)
%UNTITLED4 此处显示有关此函数的摘要
%   此处显示详细说明
n = size(A,1);
x0 = zeros(n,1);
x = b;
g = b./diag(A);
B = eye(n) - diag(ones(n,1)./diag(A))*A;
while vecnorm(x-x0)>error
    x0 = x;
    for i = 1:n
        x(i) = x(i) * (1-w) + w*g(i);
        for j = 1:n
            if j~=i
                x(i) = x(i) + w*B(i,j)*x(j);
            end
        end
    end
end
end

